package com.nyist.red2;

import java.util.concurrent.CountDownLatch;

public class QiangHongBao2 {
    public static void main(String[] args) {
        int totalMoney = 1000;
        int countNum = 50;
        int threadNum = 200;
        RedEnvelope2 redEnvelope2 = new RedEnvelope2(totalMoney, countNum);
        //创建一个CountDownLatch对象，并调用构造器将计数器设置为 threadNum
        CountDownLatch latch = new CountDownLatch(threadNum);
        UserThread2 user2 = new UserThread2(redEnvelope2, latch);
        long startTime = System.currentTimeMillis();
        for (int i = 0; i < threadNum; i++) {
            new Thread(user2).start();
        }try {
            latch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("====2222耗时为:" + (System.currentTimeMillis() - startTime));
    }
}